package com.wondersgroup.util;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtil {

  /**
   *  Json String 转换成 实体类
   *
   * @param jsonStr
   * @param clazz
   * @return
   */
  public static <T> T JsonStrinToObject(String jsonStr, Class<T> clazz) {
    ObjectMapper om = new ObjectMapper();
    T readValue = null;
    try {
      readValue = om.readValue(jsonStr, clazz);
    } catch (JsonMappingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return readValue;
  }


  public static void main(String[] args) {
    String str= "{"+"11"+":"+"2018112912"+"}";
    JSONObject jsonobject = JSONObject.parseObject(str);
    String version=jsonobject.getString("version");
    System.out.println("---"+version);
    System.out.println("--"+jsonobject.getString("sss"));
    System.out.println("--"+jsonobject.getInteger("11"));
  }
}
